package first;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @ClassName server
 * @Description TODO
 * @Author 14784
 * @Date 2020/9/24 15:12
 * @Version 1.0
 */
public class server {
    public static void main(String[] args) throws Exception {
        ServerSocket server = new ServerSocket(9091);
        try {
            Socket client = server.accept();
            try {
                BufferedReader input =
                        new BufferedReader(new InputStreamReader(client.getInputStream()));
                boolean flag = true;
                int count = 0;

                while (flag) {
                    if (count ==0){}else{
                        System.out.println("客户端发送语句，这是第 "+count+"次！");
                    }
                    count++;

                    String line = input.readLine();
                    System.out.println("客户端说： "+ line);

                    if (line.equals("exit")) {
                        flag = false;
                        System.out.println("客户端不想玩了！");
                    }
//                    else {
//                        System.out.println("客户端说：  "+ line);
//                    }

                }
            } finally {
                client.close();
                System.out.println("客户端跳出");
            }

        } finally {
            server.close();
            System.out.println("服务器跳出");
        }
    }
}
